﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8" />
    <title>查询</title>
    <link href="../Scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/bootstrap/css/font-awesome.css" rel="stylesheet" />
    <link href="../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.css" rel="stylesheet"
          type="text/css" />
    <link href="../Scripts/bootstrap/css/style.min.css" rel="stylesheet" type="text/css"
          media="all" />
    <!--jquery-->
    <script src="../Scripts/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="../Scripts/layui/layui/lay/modules/layer.js"></script>
    <link href="../Scripts/layui/layui/css/modules/layer/default/layer.css" rel="stylesheet" />
    <!--bootstrap-table-->
    <script src="../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/bootstrap-table/src/locale/bootstrap-table-zh-CN.js"
            type="text/javascript"></script>
    <script src="../Scripts/bootstrap/BootstrapUIDialog.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/bootstrap-paginator/js/bootstrap-paginator.js"
            type="text/javascript"></script>
    <script src="../Scripts/bootstrap/bootstrap-table/src/colResizable-1.6.min.js"></script>
    <script src="../Scripts/bootstrap/bootstrap-table/src/extensions/resizable/bootstrap-table-resizable.js"></script>
    <!--公共JS-->
    <script src="../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../Scripts/config.js" type="text/javascript"></script>
    <script src="Gener.js" type="text/javascript"></script>
    <script language="JavaScript" src="JScript.js" type="text/javascript"></script>
    <script src="../Comm/JS/Calendar/WdatePicker.js" type="text/javascript"></script>
    <link href="../Comm/JS/Calendar/skin/WdatePicker.css" rel="stylesheet" type="text/css" />
    <script src="../Admin/CCFlowEnum.js" type="text/javascript"></script>
    <script src="../CCForm/MapExt2016.js" type="text/javascript"></script>
    <!--serach页面JS开发接口-->
    <script src="../../DataUser/JSLibData/SearchSelf.js" type="text/javascript"></script>
    <link href="Style/Search.css" rel="stylesheet" />
    <base target="_self" />
    <style type="text/css">
        
    </style>
    <script language="javascript" type="text/javascript">
        var ensName = GetQueryString("EnsName");

        var firstLoadTable = false;
        var isCond = 0;

        //定义公共个变量.
        var webUser = new WebUser();

        //查询的文本字段
        var fields = [];

        //用户查询信息的主键
        var urMyPK = webUser.No + "_" + ensName + "_SearchAttrs";

        //页面设置信息
        var cfg = new Entity("BP.Sys.EnCfg");
        cfg.No = ensName;
        cfg.RetrieveFromDBSources();

        //当前用户查询信息.
        var ur = GetUserRegedit();

        //页面分页信息显示
        var count = ur.GetPara("RecCount");//查询总条数
        var mapBase;
        var pageIdx = this.GetQueryString("PageIdx");//当前页

        var pageSize = cfg.GetPara("PageSize");
        if (pageSize == null || pageSize == undefined || pageSize == 0)
            pageSize = 10;//一页显示的行数

        var pages = 1;//总页数
        if (count % pageSize != 0)
            pages = parseInt(count / pageSize) + 1;
        else
            pages = parseInt(count / pageSize);
        if (pages == 0) pages = 1;

        //页面字体大小
        var fontSize = cfg.GetPara("FontSize");
        if (fontSize == null || fontSize == undefined || fontSize == 0)
            fontSize = 13;

        //判断是否是多级表头
        var isThrHeader = false; //是否是三级表头
        var isSecHeader = false;//是否是二级表头
        var thrMultiTitle = cfg.GetPara("MultiTitle1"); //三级表头的内容
        var secMultiTitle = cfg.GetPara("MultiTitle");//二级表头的内容
        var firstLoadTable = false;

        //获取用户的查询信息
        function GetUserRegedit() {
            var ur = new Entity("BP.Sys.UserRegedit");
            ur.SetPKVal(urMyPK);
            ur.RetrieveFromDBSources();
            if (firstLoadTable != undefined && firstLoadTable == true) {
                //获取Url传的查询Key值
                var key = GetQueryString("Key");
                if (key != null && key != undefined && firstLoadTable == true)
                    ur.SearchKey = key;

                var dtFrom = GetQueryString("DTFrom");
                if (dtFrom != null && dtFrom != undefined && firstLoadTable == true)
                    ur.DTFrom = dtFrom;
                var dtTo = GetQueryString("DTTo");
                if (dtTo != null && dtTo != undefined && firstLoadTable == true)
                    ur.DTTo = dtTo;


            }
            return ur;
        }

        //页面启动函数.
        $(function () {

            if (webUser.No == undefined) {
                alert('登录信息丢失，请重新登录。');
                return;
            }

            if (ensName == null || ensName == undefined) {
                $("#Msg").html("必要的参数EnsName没有传入.");
                return;
            }

            $("#Msg").html("<img src=../Img/loading.gif />&nbsp;正在加载,请稍后......");

            $("#dialogExpFile").hide();

            //处理多级表头的判断
            if (thrMultiTitle == null || thrMultiTitle == undefined)
                thrMultiTitle = "";
            if (thrMultiTitle != "")
                isThrHeader = true;

            if (secMultiTitle == null || secMultiTitle == undefined)
                secMultiTitle = "";
            if (isThrHeader == false && secMultiTitle != "")
                isSecHeader = true;

            firstLoadTable = true;
            //清空Seach记录查询
            if (isCond == 1) {
                ur.MyPK = urMyPK;
                if (key != null && key != undefined)
                    ur.SearchKey = $("#TB_Key").val();
                else
                    ur.SearchKey = "";

                ur.AtPara = "";
                ur.DTFrom = "";
                ur.DTTo = "";
                ur.FK_Emp = webUser.No;
                ur.CfgKey = "SearchAttrs";
                ur.Vals = "";
                ur.FK_MapData = ensName;
                ur.Save();
            }

            //初始化工具栏.
            InitToolbar();
            //执行查询.
            BindTable();
            $("#Msg").html("");

            $("td").on("mouseover", function () {
                if (this.offsetWidth < this.scrollWidth) {
                    var that = this;
                    var text = $(this).text();
                    layer.tips(text, that, {
                        tips: 1,
                        time: 0
                    });
                }
            });
            $("td").on("mouseout", function () {
                layer.closeAll();
            });

            if (pageIdx == null || pageIdx == undefined || pageIdx == "")
                pageIdx = 1;
            //分页
            Paginator(pages, pageIdx);
            $("#SearchHtml").css("font-size", fontSize + "px");

        });

        //初始化数据.
        function InitToolbar() {

            //创建处理器.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddUrlData();  //增加参数.
            //获得map基本信息.
            mapBase = handler.DoMethodReturnJSON("Search_MapBaseInfo");

            document.title = mapBase.EnDesc;

            //获得查询信息，包含了查询数据表.
            var data = handler.DoMethodReturnJSON("Search_SearchAttrs");

            var barCount = 0; //记录查询条件，超过五个就换行
            var IsTableShow = false;
            //绑定外键枚举查询条件.
            var attrs = data["Attrs"];
            if (attrs.length > 0) {
                for (var i = 0; i < attrs.length; i++) {
                    if (attrs[i].Width >= 1000) {
                        IsTableShow = true;
                        break;
                    }
                }
            }
            var html = "";
            if (IsTableShow || 1 == 1) {
                showBarTable(attrs, data);
                return;
            }

            var searchFields = mapBase.SearchFields;
            //关键字查询
            if (searchFields == null || searchFields == "" || searchFields == undefined) {
                searchFields = "";
                if (mapBase.IsShowSearchKey == "1") {
                    var keyLabel = cfg.GetPara("KeyLabel");
                    if (keyLabel == null || keyLabel == undefined || keyLabel == "")
                        keyLabel = "关键字";
                    html += "<label  style='text-align: right; margin-top:5px;margin-left:5px;' for='TB_Key'>" + keyLabel + ":&nbsp;&nbsp</label>"
                    html += "<input style='width:140px;' type=text id='TB_Key' name='TB_Key' value='" + ur.SearchKey + "' class='form-control' />";
                    barCount += 1;
                }
                //String字段查询
            } else {
                var strs = searchFields.split("@");
                var str;
                var fieldV = "";
                var urlParamV = "";
                for (var i = 0; i < strs.length; i++) {
                    if (strs[i] == "")
                        continue;

                    str = strs[i].split("=");
                    if (str.length < 2 || str[0] == "" || str[1] == "")
                        continue;
                    fields.push(str[1]);
                    fieldV = ur.GetPara(str[1]);
                    if (fieldV == null || fieldV == undefined)
                        fieldV = "";

                    if (firstLoadTable == true) {
                        urlParamV = GetQueryString(str[1]);
                        if (urlParamV != null && urlParamV != undefined && urlParamV != "")
                            fieldV = urlParamV;
                    }


                    html += "<label  style='text-align: right; margin-top:5px;margin-left:5px;' for='TB_" + str[1] + "'>" + str[0] + ":&nbsp;&nbsp</label>"
                    html += "<input style='width:140px;' type=text id='TB_" + str[1] + "' name='TB_" + str[1] + "' value='" + fieldV + "' class='form-control' />";
                    barCount += 1;
                }
            }

            //数值型的查询增加
            var searchFieldsOfNum = mapBase.SearchFieldsOfNum;
            if (searchFieldsOfNum != null && searchFieldsOfNum != undefined && searchFieldsOfNum != "") {
                var strs = searchFieldsOfNum.split("@");
                var str;
                var fieldV = "";
                for (var i = 0; i < strs.length; i++) {
                    if (strs[i] == "")
                        continue;

                    str = strs[i].split("=");
                    if (str.length < 2 || str[0] == "" || str[1] == "")
                        continue;
                    fields.push(str[1]);
                    fieldV = ur.GetPara(str[1]);
                    if (fieldV == null || fieldV == undefined)
                        fieldV = "";

                    if (firstLoadTable == true) {
                        urlParamV = GetQueryString(str[1]);
                        if (urlParamV != null && urlParamV != undefined && urlParamV != "")
                            fieldV = urlParamV;
                    }
                    html += "<label  style='text-align: right; margin-top:5px;margin-left:5px;' for='TB_" + str[1] + "'>" + str[0] + ":&nbsp;&nbsp</label>"
                    html += "&nbsp;&nbsp;<label>>=</label>&nbsp;&nbsp<input style='width:140px;' type=text id='TB_" + str[1] + "' name='TB_" + str[1] + "' value='" + fieldV + "' class='form-control' />";
                    html += "&nbsp;&nbsp;<label><=</label>&nbsp;&nbsp<input style='width:140px;' type=text id='TB_" + str[1] + "' name='TB_" + str[1] + "' value='" + fieldV + "' class='form-control' />";
                    barCount += 2;
                }
            }


            if (mapBase.DTSearchWay != "0") {
                barCount += 2;
                html += "<label style='text-align: right; margin-top:5px;padding-left:20px;'>" + mapBase.DTSearchLable + ":&nbsp;&nbsp</label>";

                if (mapBase.DTSearchWay == "1") {
                    html += "<input type=text id='TB_DTFrom' name='TB_DTFrom' value='" + ur.DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" style='width:120px;' class='form-control' />";
                    html += "&nbsp;&nbsp;<label>到</label>&nbsp;&nbsp<input type=text id='TB_DTTo' name='TB_DTTo' value='" + ur.DTTo + "' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" style='width:140px;' class='form-control' />";
                } else {
                    html += "<input type=text id='TB_DTFrom' name='TB_DTFrom' value='" + ur.DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});\" style='width:140px;' class='form-control' />";
                    html += "&nbsp;&nbsp;<label>到</label>&nbsp;&nbsp<input type=text id='TB_DTTo' name='TB_DTTo' value='" + ur.DTTo + "' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});\"  style='width:120px;' class='form-control' />";
                }
            }

            $("#toolbar").append(html); //设置基础信息.

            //格式为: @WFSta=0@FK_Dept=02
            var json = AtParaToJson(ur.Vals);

            for (var i = 0; i < attrs.length; i++) {
                var attr = attrs[i];
                var str = "";

                str += "<label style='text-align: right; margin-top:5px;margin-left:5px;' for='DDL_" + attr.Field + "'>" + attr.Name + ":</label>";

                str += "<select class='form-control' style='margin-top:5px;width:" + attr.Width + "px' name='DDL_" + attr.Field + "' ID='DDL_" + attr.Field + "'>" + InitDDLOperation(data, attr, "all") + "</select>";
                str = $(str);

                barCount += 1;

                $("#toolbar").append(str); //设置基础信息.
            }

            html = "";
            //为查询外键赋值.
            for (var i = 0; i < attrs.length; i++) {
                var attr = attrs[i];
                var selectVal = json[attr.Field];

                if (GetQueryString(attr.Field) != null && GetQueryString(attr.Field) != undefined)
                    selectVal = GetQueryString(attr.Field);

                if (selectVal == undefined || selectVal == "")
                    selectVal = "all";

                //判断是否有级联关系
                var myPK = "ActiveDDL_" + ensName + "_" + attr.Field;
                var mapExt = new Entity("BP.Sys.MapExt");
                mapExt.SetPKVal(myPK);
                var isExist = mapExt.RetrieveFromDBSources();
                //处理级联关系
                if (isExist == 1) {
                    var ddlPerant = $("#DDL_" + mapExt.AttrOfOper);
                    var ddlChild = $("#DDL_" + mapExt.AttrsOfActive);
                    if (ddlPerant != null && ddlChild != null) {
                        ddlPerant.attr("onchange", "DDLRelation(this.value,\'" + "DDL_" + mapExt.AttrsOfActive + "\', \'" + mapExt.MyPK + "\',\'" + ddlPerant.val() + "\')");

                    }
                }
                if (firstLoadTable == true) {
                    var urlParamV = GetQueryString(attr.Field);
                    if (urlParamV != null && urlParamV != undefined && urlParamV != "")
                        selectVal = urlParamV;
                }


                $("#DDL_" + attr.Field).val(selectVal);
            }

            html += '<a href="#"class="btn btn-primary btn-sm" style="margin-left:20px" id="search_btn" onclick="Search()">查询</a>  ';
            var btnLab1 = cfg.GetPara("BtnLab1");
            var btnLab2 = cfg.GetPara("BtnLab2");
            if (btnLab1 != null && btnLab1 != undefined && btnLab1 != "")
                html += "&nbsp;<a href='#'class='btn btn-default btn-sm'   onclick='executeFunction(\"" + cfg.GetPara("BtnJS1") + "\",\"" + btnLab1 + "\")'>" + btnLab1 + "</a>";

            if (btnLab2 != null && btnLab2 != undefined && btnLab2 != "")
                html += "&nbsp;<a href='#'class='btn btn-default btn-sm'   onclick='executeFunction(\"" + cfg.GetPara("BtnJS2") + "\",\"" + btnLab2 + "\")'>" + btnLab2 + "</a>";

            if (mapBase.IsInsert.toString().toLowerCase() == "true") {
                html += '<a href="#" class="btn btn-default btn-sm" id="new_btn" onclick="New()">新建</a>  ';
            }
            html += '<a href="#" class="btn btn-default btn-sm" id="exp_btn" onclick="Exp()">导出</a>  ';

            if (mapBase.IsImp.toString().toLowerCase() == "true")
                html += '<a href="#" class="btn btn-default btn-sm" id="imp_btn" onclick="Imp()">导入</a>';

            var webUser = new WebUser();
            if (webUser.No == "admin")
                html += '<a href="#" class="btn btn-default btn-sm" id="setting_btn" onclick="Setting()">设置</a>';

            $("#toolbar").append(html);

        }

        function showBarTable(attrs, data) {
            var html = "";
            var searchFields = mapBase.SearchFields;
            if (searchFields == null || searchFields == "" || searchFields == undefined)
                searchFields = "";
            var len = 0;
            if (searchFields != "")
                len = searchFields.split("@").length;
            len = parseInt(attrs.len) + length;
            var searchFieldsOfNum = mapBase.SearchFieldsOfNum;
            var countNum = 5;
            if (searchFieldsOfNum != null && searchFieldsOfNum != undefined && searchFieldsOfNum != "")
                countNum = 4;

            if (mapBase.DTSearchWay == "0") {
                if (len == 0)
                    html += "<table style='width:30%;' >";
                if (len == 1)
                    html += "<table style='width:50%;' >";
            } else {
                if (len == 0)
                    html += "<table style='width:60%;' >";
                if (len == 1)
                    html += "<table style='width:80%;' >";
            }

            if (len > 1)
                html += "<table style='width:100%;' >";


            html += "<tr>";

            //关键字查询
            if (searchFields == "") {
                if (mapBase.IsShowSearchKey == "1") {
                    var keyLabel = cfg.GetPara("KeyLabel");
                    if (keyLabel == null || keyLabel == undefined || keyLabel == "")
                        keyLabel = "关键字";
                    html += "<td align='right'><label  style='text-align: right; margin-top:5px;margin-left:5px;' for='TB_Key'>" + keyLabel + ":</label></td>";
                    html += "<td align='left'><input style='width:100%;' type=text id='TB_Key' name='TB_Key' value='" + ur.SearchKey + "' class='form-control' /></td>";
                }
                //String字段查询
            } else {
                var strs = searchFields.split("@");
                var fieldV = "";
                var count = 0;
                for (var i = 0; i < strs.length; i++) {
                    if (strs[i] == "")
                        continue;

                    var str = strs[i].split("=");
                    if (str.length < 2 || str[0] == "" || str[1] == "")
                        continue;
                    fields.push(str[1]);

                    fieldV = ur.GetPara(str[1]);
                    if (fieldV == null || fieldV == undefined)
                        fieldV = "";
                    count++;
                    html += "<td align='right'><label  style='text-align: right; margin-top:5px;margin-left:5px;' for='TB_" + str[1] + "'>" + str[0] + ":</label></td>";
                    html += "<td align='left'><input style='width:100%;' type=text id='TB_" + str[1] + "' name='TB_" + str[1] + "' value='" + fieldV + "' class='form-control' /></td>";
                    if (count == countNum) {
                        count = 0;
                        html += "</tr>";
                        html += "<tr>";
                    }
                }
            }

            //数值型的查询增加

            var val1 = "";
            var val2 = "";
            if (searchFieldsOfNum != null && searchFieldsOfNum != undefined && searchFieldsOfNum != "") {
                var strs = searchFieldsOfNum.split("@");
                var str;
                var fieldV = "";
                for (var i = 0; i < strs.length; i++) {
                    if (strs[i] == "")
                        continue;

                    str = strs[i].split("=");
                    if (str.length < 2 || str[0] == "" || str[1] == "")
                        continue;
                    fields.push(str[1]);
                    fieldV = ur.GetPara(str[1]);
                    if (fieldV == null || fieldV == undefined || fieldV == "") {
                        val1 = "";
                        val2 = "";
                    } else {
                        val1 = fieldV.split(',')[0];
                        val2 = fieldV.split(',')[1];
                    }



                    html += "<td align='right'><label  style='text-align: right; margin-top:5px;margin-left:5px;' for='TB_" + str[1] + "'>" + str[0] + ":</label></td>";
                    html += "<td align='left'><input style='width:80px;min-width:80px;' type=text id='TB_" + str[1] + "_0' name='TB_" + str[1] + "' value='" + val1 + "' class='form-control' />";
                    html += "<label>&nbsp;&nbsp;～&nbsp;&nbsp</label><input style='width:80px;min-width:80px;' type=text id='TB_" + str[1] + "_1' name='TB_" + str[1] + "' value='" + val2 + "' class='form-control' /></td>";
                    count++;
                    if (count >= countNum) {
                        count = 0;
                        html += "</tr>";
                        html += "<tr>";
                    }

                }
            }

            if (mapBase.DTSearchWay != "0") {
                html += "<td align='right'><label style='text-align: right; margin-top:5px;padding-left:20px;'>" + mapBase.DTSearchLable + ":</label></td>";

                if (mapBase.DTSearchWay == "1") {
                    html += "<td align='left'><input type=text id='TB_DTFrom' name='TB_DTFrom' value='" + ur.DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" style='width:120px;' class='form-control Wdate' /></td>";
                    html += "<td align='left'>&nbsp;<label>到</label>&nbsp;&nbsp<input type=text id='TB_DTTo' name='TB_DTTo' value='" + ur.DTTo + "' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" style='width:120px;' class='form-control Wdate' /></td>";
                } else {
                    html += "<td align='left'><input type=text id='TB_DTFrom' name='TB_DTFrom' value='" + ur.DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});\" style='width:140px;' class='form-control Wdate' /></td>";
                    html += "<td align='left'>&nbsp;<label>到</label>&nbsp;&nbsp<input type=text id='TB_DTTo' name='TB_DTTo' value='" + ur.DTTo + "' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});\"  style='width:140px;' class='form-control Wdate' /></td>";
                }
            }


            //格式为: @WFSta=0@FK_Dept=02
            var json = AtParaToJson(ur.Vals);

            for (var i = 0; i < attrs.length; i++) {
                var attr = attrs[i];
                var W = attr.Width;
                if (attr.Width >= 1000) {
                    html += "</tr>";
                    html += "<tr>";
                    W = 130;
                }

                html += "<td align='right'><label style='text-align: right; margin-top:5px;margin-left:5px;' for='DDL_" + attr.Field + "'>" + attr.Name + ":</label></td>";
                html += "<td align='left'><select class='form-control' style='margin-top:5px;width:100%;' name='DDL_" + attr.Field + "' ID='DDL_" + attr.Field + "'>" + InitDDLOperation(data, attr, "all") + "</select></td>";
            }

            //增加按钮.
            html += '<td align="left" colspan=2 ><a href="#"class="btn btn-primary btn-sm" style="margin-left:10px" id="search_btn" onclick="Search()">查询</a>  ';

            var btnLab1 = cfg.GetPara("BtnLab1");
            var btnLab2 = cfg.GetPara("BtnLab2");
            if (btnLab1 != null && btnLab1 != undefined && btnLab1 != "")
                html += "&nbsp;<a href='#'class='btn btn-default btn-sm'  onclick='executeFunction(\"" + cfg.GetPara("BtnJS1") + "\",\"" + btnLab1 + "\")'>" + btnLab1 + "</a>";

            if (btnLab2 != null && btnLab2 != undefined && btnLab2 != "")
                html += "&nbsp;<a href='#'class='btn btn-default btn-sm'   onclick='executeFunction(\"" + cfg.GetPara("BtnJS2") + "\",\"" + btnLab2 + "\")'>" + btnLab2 + "</a>";

            if (mapBase.IsInsert.toString().toLowerCase() == "true")
                html += '&nbsp;<a href="#" class="btn btn-default btn-sm" id="new_btn" onclick="New()">新建</a>';

            html += '&nbsp;<a href="#" class="btn btn-default btn-sm" id="exp_btn" onclick="Exp()">导出</a>';

            if (mapBase.IsImp.toString().toLowerCase() == "true")
                html += '&nbsp;<a href="#" class="btn btn-default btn-sm" id="exp_btn" onclick="Imp()">导入</a> ';
            if (new WebUser().No == "admin")
                html += '&nbsp;<a href="#" class="btn btn-default btn-sm" id="setting_btn" onclick="Setting()">设置</a>';

            html += "</td></tr>";

            html += "</table>";

            $("#toolbar").append(html);

            //为查询外键赋值.
            for (var i = 0; i < attrs.length; i++) {
                var attr = attrs[i];
                var selectVal = json[attr.Field];
                if (GetQueryString(attr.Field) != null && GetQueryString(attr.Field) != undefined)
                    selectVal = GetQueryString(attr.Field);

                if (selectVal == undefined || selectVal == "")
                    selectVal = "all";
                //判断是否有级联关系
                var myPK = "ActiveDDL_" + ensName + "_" + attr.Field;
                var mapExt = new Entity("BP.Sys.MapExt");
                mapExt.SetPKVal(myPK);
                var isExist = mapExt.RetrieveFromDBSources();
                //处理级联关系
                if (isExist == 1) {
                    var ddlPerant = $("#DDL_" + mapExt.AttrOfOper);
                    var ddlChild = $("#DDL_" + mapExt.AttrsOfActive);
                    if (ddlPerant != null && ddlChild != null) {
                        ddlPerant.attr("onchange", "DDLRelation(this.value,\'" + "DDL_" + mapExt.AttrsOfActive + "\', \'" + mapExt.MyPK + "\',\'" + ddlPerant.val() + "\')");

                    }
                }

                $("#DDL_" + attr.Field).val(selectVal);
            }
        }



        //初始化下拉列表框的OPERATION
        function InitDDLOperation(frmData, mapAttr, defVal) {

            var operations = "";
            operations += "<option value='all' >全部</option>";

            var ens = frmData[mapAttr.Field];
            if (ens == null) {
                ens = [{ 'IntKey': 0, 'Lab': '否' }, { 'IntKey': 1, 'Lab': '是' }];
            }
            for (var i = 0; i < ens.length; i++) {

                var en = ens[i];

                if (en.No == undefined)
                    operations += "<option value='" + en.IntKey + "'>" + en.Lab + "</option>";
                else
                    operations += "<option value='" + en.No + "'>" + en.Name + "</option>";
            }
            return operations;
        }

        //执行查询.
        function Search() {

            //保存查询条件.
            var ensName = GetQueryString("EnsName");
            ur = GetUserRegedit();
            if ($("#TB_Key") != null && $("#TB_Key").val() != "")
                ur.SearchKey = $("#TB_Key").val();
            else
                ur.SearchKey = "";

            //增加字段查询
            var val = "";
            for (var i = 0; i < fields.length; i++) {
                var field = fields[i];
                var strs = $("input[name='TB_" + field + "']");
                if (strs.length == 1) {
                    ur.SetPara(field, $("#TB_" + field).val());
                } else {
                    if ($("#TB_" + field + "_0").val() == "" && $("#TB_" + field + "_1").val() == "")
                        ur.SetPara(field, "");
                    else
                        ur.SetPara(field, $("#TB_" + field + "_0").val() + "," + $("#TB_" + field + "_1").val());
                }


            }

            //设置查询时间.
            if ($("#TB_DTFrom").length == 1)
                ur.DTFrom = $("#TB_DTFrom").val();

            if ($("#TB_DTTo").length == 1)
                ur.DTTo = $("#TB_DTTo").val();

            //获得外键的查询条件,存储里面去.
            var str = "";
            $("select[name^='DDL_']").each(function () {
                var id = $(this).attr("id");
                id = id.replace("DDL_", "");
                str += "@" + id + "=" + $(this).val();
            });

            ur.FK_Emp = webUser.No;
            ur.CfgKey = "SearchAttrs";
            ur.Vals = str;
            ur.FK_MapData = ensName;
            ur.SetPara("RecCount", count);
            var i = ur.Update();
            pageIdx = 1;
            SearchData();
            //分页
            Paginator(pages, pageIdx);
        }


        function SearchData(orderBy, orderWay) {
            ur = GetUserRegedit()
            //创建处理器.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddUrlData()
            handler.AddPara("PageIdx", pageIdx);
            handler.AddPara("PageSize", pageSize);
            if (orderBy != null && orderBy != undefined)
                ur.OrderBy = orderBy;
            if (orderWay != null && orderWay != undefined)
                ur.OrderWay = orderWay;
            ur.Update();
            //查询集合
            var data = handler.DoMethodReturnString("Search_SearchIt");
            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            data = JSON.parse(data);
            //当前用户页面信息.

            ur.MyPK = webUser.No + "_" + ensName + "_SearchAttrs";
            ur.SetPKVal(ur.MyPK);
            ur.RetrieveFromDBSources();
            count = ur.GetPara("RecCount");
            if (count % pageSize != 0)
                pages = parseInt(count / pageSize) + 1;
            else
                pages = parseInt(count / pageSize);

            if (pages == 0) pages = 1;

            if (firstLoadTable == false) {
                $('#dg').bootstrapTable("load", data["DT"]);

                $("td").on("mouseover", function () {
                    if (this.offsetWidth < this.scrollWidth) {
                        var that = this;
                        var text = $(this).text();
                        layer.tips(text, that, {
                            tips: 1,
                            time: 0
                        });
                    }
                });
                $("td").on("mouseout", function () {
                    layer.closeAll();
                });
                return;
            }

            //设置查询总数居的合计、平均等信息
            var heji = data["Search_HeJi"];
            var _html = "";
            if (heji != null && heji != undefined) {
                $.each(heji, function (i, item) {
                    var val = item.Value;
                    if (val == null || val == "" || val == undefined)
                        val = 0;
                    if (item.Type == "Sum")
                        _html += item.Field + "总合计：" + val + " ";
                    if (item.Type == "Avg")
                        _html += item.Field + "总平均：" + val + " ";
                });
            }


            $("#JsResult").html("").html(_html);
            return data;
        }

        //生成查询页面..
        function BindTable() {
            //获得外键的查询条件,存储里面去.
            var str = "";
            $("select[name^='DDL_']").each(function () {
                var id = $(this).attr("id");
                id = id.replace("DDL_", "");
                str += "@" + id + "=" + $(this).val();
            });
            ur = GetUserRegedit()
            ur.Vals = str;
            ur.Update();
            //获取页面的高度
            var H = document.body.clientHeight;
            var tableH = H - $("#toolbar").outerHeight() - $("#page-nav").outerHeight() - 70;

            if (pageIdx == "" || pageIdx == undefined)
                pageIdx = "1";
            if (pageSize == "" || pageSize == undefined)
                pageSize = "20";


            var mapdata = SearchData();
            var attrs = mapdata["Attrs"];

            var dtMs = mapdata["dtM"];

            var sysMapData = mapdata["Sys_MapData"][0];
            sysMapData = new Entity("BP.Sys.MapData", sysMapData); //把他转化成entity.
            var enPK = sysMapData.GetPara("PK");

            if (attrs == undefined) {
                alert('没有取得属性.');
                return;
            }

            var keyOfEn = "";

            var focusField = "";
            if (cfg.GetPara("IsEnableFocusField") == "1")
                focusField = cfg.GetPara("FocusField");



            var firstColumns = new Array();
            var secondColumns = new Array();
            var threeColumns = new Array();

            var fieldColumns = {
                title: '序',
                field: '',
                align: 'center',
                width: 25,
                rowspan: isThrHeader == true ? 3 : isSecHeader == true ? 2 : 1,
                formatter: function (value, row, index) {
                    return pageSize * (pageIdx - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
                }
            };
            AddColumn(fieldColumns, firstColumns, secondColumns, threeColumns, isThrHeader == true ? 3 : isSecHeader == true ? 2 : 1);

            //颜色设置
            var colorSet = cfg.ColorSet;

            for (var i = 0; i < attrs.length; i++) {
                var attr = attrs[i];

                if (attr.UIVisible == 0
                    || attr.KeyOfEn == "OID"
                    || attr.KeyOfEn == "WorkID"
                    || attr.KeyOfEn == "NodeID"
                    || attr.KeyOfEn == "MyNum"
                    || attr.KeyOfEn == "MyPK") {
                    keyOfEn = attr.KeyOfEn
                    continue;
                }
                var keyRowSpan = GetAttrKeyRowSpan(attr.KeyOfEn);
                if (keyRowSpan == 3 && thrcolspan.field != undefined) {
                    threeColumns.push(thrcolspan);
                    thrcolspan = {};
                }

                //是否增加二级或者三级分组
                if ((isSecHeader == true && keyRowSpan == 1)
                    || isThrHeader == true && keyRowSpan != 3)
                    AddSecOrThrColumn(attr.KeyOfEn, keyRowSpan, secondColumns, threeColumns);



                var field = attr.KeyOfEn;

                var width = attr.Width;
                if (width < 60) {
                    width = 60;
                }
                if (field == "Title") {
                    width = 230;
                }
                var title = attr.Name;
                if (attr.UIContralType == 1) {
                    if (width == null || width == "" || width == undefined)
                        width = 180;
                    field = field + "Text";
                    fieldColumns = {
                        field: field,
                        title: title,
                        fixed: false,
                        width: width,
                        sortable: true,
                        rowspan: keyRowSpan,
                        cellStyle: {
                            css: { "white-space": "nowrap", "word-break": "keep-all", "width": "100%" }
                        }
                    };
                    AddColumn(fieldColumns, firstColumns, secondColumns, threeColumns, keyRowSpan);
                    continue;
                }
                if (attr.UIContralType == 2) {
                    fieldColumns = {
                        field: field,
                        title: title,
                        width: width,
                        fixed: false,
                        sortable: true,
                        rowspan: keyRowSpan,
                        formatter: function (value, row, index) {
                            if (value == "0") return "否";
                            if (value == "1") return "是";
                        }
                    };
                    AddColumn(fieldColumns, firstColumns, secondColumns, threeColumns, keyRowSpan);
                    continue;
                }
                if (width == null || width == "" || width == undefined)
                    width = 100;

                fieldColumns = {
                    field: field,
                    title: title,
                    width: width,
                    fixed: false,
                    sortable: true,
                    rowspan: keyRowSpan,
                    formatter: function (value, row, index) {
                        if (this.field == focusField) {
                            var pkval = row[enPK];
                            var paras = "&" + enPK + "=" + pkval;
                            for (var i = 0; i < attrs.length; i++) {
                                var attr = attrs[i];
                                if (attr.UIContralType == 1)
                                    paras += "&" + attr.KeyOfEn + "=" + row[attr.KeyOfEn];
                            }
                            var rowstr = JSON.stringify(row);
                            rowstr = encodeURIComponent(rowstr);
                            return "<a href='#' onclick='OpenEn(\"" + pkval + "\",\"" + paras + "\",1,\"" + rowstr + "\")'>" + value + "</a>";
                        }




                        var fieldColor = [];
                        if (colorSet.indexOf("@" + this.field + ":") != -1) {
                            fieldColor = getFieldColor(colorSet, this.field);
                        }
                        if (fieldColor.length == 0)
                            return value;
                        for (var i = 0; i < fieldColor.length; i++) {
                            var color = fieldColor[i];
                            if (color.From <= value && color.To >= value)
                                return "<div style='width:20px;height:20px;text-align:center;background:" + color.Color + "'>" + value + "</div>";
                        }
                    }

                };
                AddColumn(fieldColumns, firstColumns, secondColumns, threeColumns, keyRowSpan);
            }
            if (thrcolspan.field != undefined)
                threeColumns.push(thrcolspan);
            //获取屏幕的长宽
            var W = document.body.clientWidth - 40;
            var H = document.body.clientHeight - 40;
            var entityAthType = sysMapData.GetPara("BPEntityAthType");
            if (dtMs.length > 0 || entityAthType == 1 || entityAthType == 2) {
                fieldColumns = {
                    field: '_operate',
                    title: '操作',
                    width: 200,
                    align: 'center',
                    rowspan: isThrHeader == true ? 3 : isSecHeader == true ? 2 : 1,
                    formatter: function (value, row, index) {
                        var pkval = row[enPK];
                        var html = "";
                        for (var k = 0; k < dtMs.length; k++) {
                            var dtm = dtMs[k];
                            var isShowForEnsCondtion = dtm.IsShowForEnsCondtion;
                            if (isShowForEnsCondtion != null && isShowForEnsCondtion != "") {
                                var strs = isShowForEnsCondtion.split("@");
                                var isShow = true;
                                $.each(strs, function (i, obj) {
                                    var items = obj.split("=");
                                    if (row[items[0]] != items[1]) {
                                        isShow = false;
                                        return true;
                                    }
                                });
                                if (isShow == false)
                                    continue;
                            }
                            var warning = dtm.Warning;
                            var refMethodType = parseInt(dtm.RefMethodType);
                            var url = dtm.Url + pkval;
                            switch (refMethodType) {
                                case RefMethodType.LinkeWinOpen:
                                    html += "<a href='#' onclick='WinOpenIt(\"" + url + "\",\"" + dtm.Title + "\")'>" + dtm.Title + "</a>&nbsp;&nbsp;";
                                    break;
                                case RefMethodType.LinkModel:
                                case RefMethodType.RightFrameOpen:
                                    html += "<a href='#' onclick='OpenBootStrapModal(\"" + url + "\",\"eudlgframe\",\"" + dtm.Title + "\"," + W + "," + H + ",\"icon-property\", null, null, null, null, null, \"black\")'>" + dtm.Title + "</a>&nbsp;&nbsp;";
                                    break;
                                case RefMethodType.Func:
                                    if (dtm.FunPara == true || dtm.FunPara == "true")
                                        html += "<a href='#' onclick='OpenBootStrapModal(\"" + url + "\",\"eudlgframe\",\"" + dtm.Title + "\"," + W + "," + H + ",\"icon-property\", null, null, null, null, null, \"black\")'>" + dtm.Title + "</a>&nbsp;&nbsp;";
                                    else {
                                        if (warning == null || warning == "null" || warning == "") {
                                            warning = "确定要执行吗？";
                                        }
                                        else {
                                            warning = warning.replace(/,\s+/g, ",");
                                            warning = warning.replace(/\s+/g, "\r\n");
                                        }
                                        html += "<a href='#' onclick='openFun(\"" + warning + "\",\"" + url + "\",\"" + dtm.Title + "\")'>" + dtm.Title + "</a>&nbsp;&nbsp;";

                                    }

                                    break;
                                default: break;
                            }
                        }
                        html += formatOper(value, row, index);
                        if (html == "")
                            html = "-";

                        return html;

                    }
                }
                AddColumn(fieldColumns, firstColumns, secondColumns, threeColumns, isThrHeader == true ? 3 : isSecHeader == true ? 2 : 1);
            }

            var isEnableOpen = cfg.GetPara("IsEnableOpenICON");
            //添加显示详情列
            if (isEnableOpen == "1") {
                //加入操作下载文件
                fieldColumns = {
                    field: 'viewDetail',
                    title: '详细信息',
                    width: 80,
                    align: 'center',
                    rowspan: isThrHeader == true ? 3 : isSecHeader == true ? 2 : 1,
                    formatter: function (value, row, index) {
                        var pkval = row[enPK];
                        var paras = "&" + enPK + "=" + pkval;
                        for (var i = 0; i < attrs.length; i++) {
                            var attr = attrs[i];
                            if (attr.UIContralType == 1)
                                paras += "&" + attr.KeyOfEn + "=" + row[attr.KeyOfEn];
                        }
                        var rowstr = JSON.stringify(row);
                        rowstr = encodeURIComponent(rowstr);
                        return "<a href='#' onclick='OpenEn(\"" + pkval + "\",\"" + paras + "\",1,\"" + rowstr + "\")'>详情</a>";
                    }
                }
                AddColumn(fieldColumns, firstColumns, secondColumns, threeColumns, isThrHeader == true ? 3 : isSecHeader == true ? 2 : 1);
            }
            var columns = new Array();
            if (isThrHeader == false && isSecHeader == false)
                columns[0] = firstColumns;
            if (isSecHeader == true) {
                columns[0] = secondColumns;
                columns[1] = firstColumns;
            }

            if (isThrHeader == true) {
                columns[0] = threeColumns;
                columns[1] = secondColumns;
                columns[2] = firstColumns;
            }




            $('#dg').html("");
            $('#dg').bootstrapTable({
                data: mapdata["DT"],
                columns: columns,
                cache: false,
                striped: true,
                height: tableH,
                singleSelect: true,
                sidePagination: "client",
                pageNumber: 1,
                strictSearch: true,
                showMultiSort: true, // 多列排序
                rememberOrder: true,//记住每个列的排序
                onSort: function (name, order) {
                    pageIdx = 1;
                    SearchData(name, order);
                    Paginator(pages, 1)
                },
                showMultiSort: true, // 多列排序
                //得到查询的参数
                queryParams: function (params) {
                    //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    var temp = {
                        rows: 10,                         //页面大小
                        page: (count / 10) + 1,   //页码

                    };
                    return temp;
                },

                onDblClickRow: function (row, $element) {
                    var pkval = row[enPK];
                    var paras = "&" + enPK + "=" + pkval;
                    for (var i = 0; i < attrs.length; i++) {
                        var attr = attrs[i];
                        if (attr.UIContralType == 1)
                            paras += "&" + attr.KeyOfEn + "=" + row[attr.KeyOfEn];
                    }

                    OpenEn(pkval, paras, 1, encodeURIComponent(JSON.stringify(row)));
                }

            });
            $("#dg").colResizable({
                liveDrag: true,
                gripInnerHtml: "<div class='grip'></div>",
                draggingClass: "dragging",
                resizeMode: 'fit',
                //拖动事件
                onDrag: function () {
                    $('#dg').bootstrapTable("resetView")
                }
            });
            firstLoadTable = false;

        }

        /**
         * 把列增加到对应的数组中
         * @param column 列信息
         * @param firstColumns 一级表头数组
         * @param secondColumns 二级表头数组
         * @param threeColumns 三级表头数组
         * @param columnIdx 隶属那个表头
         */
        function AddColumn(column, firstColumns, secondColumns, threeColumns, columnIdx) {
            if (columnIdx == 1)
                firstColumns.push(column);
            if (columnIdx == 2)
                secondColumns.push(column);
            if (columnIdx == 3)
                threeColumns.push(column);

        }

        /**
         * 获取数据字段跨的行数
         * @param keyOfEn
         */
        function GetAttrKeyRowSpan(keyOfEn) {
            //一级表头
            if (isThrHeader == false && isSecHeader == false)
                return 1;
            //先判断是否是隶属于二级表头下的字段
            if (secMultiTitle.indexOf("," + keyOfEn + ",") != -1)
                return 1;
            //是否是隶属于三级表头下的字段
            if (thrMultiTitle.indexOf("," + keyOfEn + ",") != -1)
                return 2;
            return isThrHeader == true ? 3 : 2;

        }
        /**
         * 增加二级或三级表头的分组
         * @param keyOfEn
         * @param keyRowSpan
         * @param secondColumns
         * @param threeColumns
         */
        var curSecGroup = "";
        var curTreGroup = "";
        var thrcolspan = {};
        var isSecChange = false;
        function AddSecOrThrColumn(keyOfEn, keyRowSpan, secondColumns, threeColumns) {
            //计算二级表头分组
            var secfilds = getMutliFile(keyOfEn, secMultiTitle);
            var secRowSpan = 1;
            if (isSecHeader == true && keyRowSpan == 1)
                secRowSpan = 1;
            if (isThrHeader == true && keyRowSpan == 1) {
                if (thrMultiTitle.indexOf("," + secfilds[0] + ",") == -1)
                    secRowSpan = 2;
                else
                    secRowSpan = 1;
            }
            if (isThrHeader == true && keyRowSpan == 2)
                secRowSpan = 0;
            //增加二级表头
            if (secRowSpan == 1) {
                var colspan = secfilds.length - 1;
                if (curSecGroup == "" || curSecGroup != secfilds[0]) {
                    curSecGroup = secfilds[0];
                    isSecChange = true;
                    secondColumns.push({
                        title: secfilds[0],
                        field: '',
                        align: 'center',
                        colspan: colspan,
                        rowspan: secRowSpan
                    });
                } else {
                    isSecChange = false;
                }
                //增加三级表头
                if (isThrHeader == true && secRowSpan == 1) {
                    var filds = getMutliFile(secfilds[0], thrMultiTitle);
                    if (curTreGroup == "" || curTreGroup != filds[0]) {
                        //增加三级表头
                        if (curTreGroup != "" && curTreGroup != filds[0]) {
                            threeColumns.push(thrcolspan);
                            thrcolspan = {};
                        }
                        thrcolspan = {
                            title: filds[0],
                            field: '',
                            align: 'center',
                            colspan: colspan,
                        }

                        curTreGroup = filds[0];
                    } else {
                        if (isSecChange == true)
                            thrcolspan.colspan = thrcolspan.colspan + colspan;
                    }


                }
            }
            //三级表头
            if (secRowSpan == 2) {
                if (thrcolspan.title != undefined) {
                    threeColumns.push(thrcolspan);
                    thrcolspan = {};
                }
                if (curTreGroup == "" || curTreGroup != secfilds[0]) {
                    curTreGroup = secfilds[0];
                    threeColumns.push({
                        title: secfilds[0],
                        field: '',
                        align: 'center',
                        colspan: secfilds.length - 1,
                        rowspan: secRowSpan
                    });
                }
            }

            if (secRowSpan == 0) {
                filds = getMutliFile(keyOfEn, thrMultiTitle);
                if (curTreGroup == "" || curTreGroup != filds[0]) {
                    //增加三级表头
                    if (curTreGroup != "" && curTreGroup != filds[0]) {
                        threeColumns.push(thrcolspan);
                    }
                    thrcolspan = {
                        title: filds[0],
                        field: '',
                        align: 'center',
                        colspan: 1,
                    };
                    curTreGroup = filds[0];
                } else {
                    thrcolspan.colspan = thrcolspan.colspan + 1;
                }


            }

        }
        function getMutliFile(keyOfEn, multi) {
            var fields = multi.split(";");
            for (var i = 0; i < fields.length; i++) {
                var str = fields[i];
                if (str == "")
                    continue;
                if (str.indexOf("," + keyOfEn + ",") == -1)
                    continue;
                var strs = str.substring(0, str.length - 1).split(",");
                return strs;
            }
            return "";
        }

        //分页功能
        function Paginator(pageCount, currentPage) {
            var pageCount = pageCount; //取到pageCount的值(把返回数据转成object类型)
            var options = {
                bootstrapMajorVersion: 3, //版本
                currentPage: currentPage, //当前页数
                totalPages: pageCount, //总页数
                shouldShowPage: true, //是否显示该按钮
                itemTexts: function (type, page, current) {
                    switch (type) {
                        case "first":
                            return "首页";
                        case "prev":
                            return "上一页";
                        case "next":
                            return "下一页";
                        case "last":
                            return "末页";
                        case "page":
                            return page;
                    }
                }, //点击事件，用于通过Ajax来刷新整个list列表
                onPageClicked: function (event, originalEvent, type, page) {
                    pageIdx = page;
                    SearchData(page);
                    $('#page_info').html("").append("<li class='disabled controls'>当前第" + pageIdx + "页，总共" + pages +
                        "页,总共" + count + "条记录。</li>");
                }
            };
            $('#page_nav').bootstrapPaginator(options);
            $('#page_info').html("").append("<li class='disabled controls'>当前第" + pageIdx + "页，总共" + pages +
                "页,总共" + count + "条记录。</li>");

        }


        function operate(value, row, index) {
            return '<a href="#" onclick="editUser(' + index + ')">查看明细</a>';
        }

        function OpenEn(pk, paras, flag, row) {

            if (row != null && row != undefined && row != "")
                row = JSON.parse(decodeURIComponent(row));
            //当前URL参数
            var currUrl = window.location.search.substring(1);
            //去除URL中的参数 EnsName、 PKVal
            var currUrls = currUrl.split("&");
            currUrl = "";
            $.each(currUrls, function (i, param) {
                if (param.indexOf("EnsName") == -1 && param.indexOf("PKVal") == -1)
                    currUrl += "&" + param;
            });

            var ensName = GetQueryString("EnsName");
            var enName = ensName.substring(0, ensName.length - 1);
            //考虑兼容旧版本.
            var url = cfg.GetPara("WinOpenUrl");
            if (url && url.length > 4) {
                cfg.Url = url;
                cfg.Update();
            }

            url = cfg.UrlExt;
            var urlOpenType = cfg.SearchUrlOpenType;

            if (urlOpenType == 0 || urlOpenType == undefined)
                url = "./RefFunc/En.htm?EnName=" + mapBase.EnName + "&PKVal=" + pk + currUrl;

            if (urlOpenType == 1)
                url = "./RefFunc/EnOnly.htm?EnName=" + mapBase.EnName + "&PKVal=" + pk + currUrl;

            if (urlOpenType == 2)
                url = "../CCForm/FrmGener.htm?FK_MapData=" + GetQueryString("EnsName") + "&PKVal=" + pk + currUrl;

            if (urlOpenType == 3)
                url = "../CCForm/FrmGener.htm?FK_MapData=" + GetQueryString("EnsName") + "&PKVal=" + pk + currUrl;

            if (urlOpenType == 9) {
                if (url.indexOf('?') == -1)
                    url = url + "?1=1";
                if (url.indexOf('FrmID') != -1)
                    url = url + "&WorkID=" + pk + "&OID=" + pk;
            }

            //url中包含@符号需要进行替换
            if (url.indexOf("@") != -1) {
                url = DealJsonExp(row, url);
            }

            var windowW = cfg.WinCardW;
            if (windowW == "" || windowW == undefined)
                windowW = 900;

            var windowH = cfg.WinCardH;
            if (windowH == "" || windowH == undefined)
                windowH = 500;

            var openModel = cfg.OpenModel;
            if (openModel == 0) {
                OpenBootStrapModal(url, "eudlgframe", mapBase.EnDesc + ' : 详细', windowW, windowH, "icon-property", null, null, null, function () {
                    if (flag == 0 || cfg.IsRefreshParentPage == 1) {
                        SearchData();
                        Paginator(pages);
                    }


                }, null, 'black');
            } else {
                var windowObj = window.open(url);
                if (flag == 0 || cfg.IsRefreshParentPage == 1) {
                    var loop = setInterval(function () {
                        if (windowObj.closed) {
                            clearInterval(loop);
                            SearchData();
                            Paginator(pages);

                        }

                    }, 1000);
                }
            }


        }

        /**
         * 获取字段的设置
         * @param colorSet  颜色总体设置
         * @param keyOfEn 字段
         */
        function getFieldColor(colorSet, keyOfEn) {
            var fieldColor = [];
            var colorSets = colorSet.split('@');
            for (var i = 0; i < colorSets.length; i++) {
                if (colorSets[i] == "")
                    continue;
                var strs = colorSets[i].split(':');
                if (strs.length == 0 || strs.length == 1)
                    continue;
                if (strs[0] != keyOfEn)
                    continue;
                var ss = strs[1].split(';');
                for (var k = 0; k < ss.length; k++) {
                    if (ss[k] == "")
                        continue;
                    var ts = ss[k].split(',');
                    if (ts.length < 3) {
                        alert('字段' + keyOfEn + '范围颜色设置格式错误');
                        break;
                    }

                    fieldColor.push({
                        "From": parseInt(ts[0].replace("From=", "")),
                        "To": parseInt(ts[1].replace("To=", "")),
                        "Color": ts[2].replace("Color=", "")
                    });
                }



            }
            return fieldColor;
        }
        function New() {
            OpenEn("", "", 0, null);
        }

        function Exp() {

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddPara("EnsName", GetQueryString("EnsName"));
            //查询集合
            var data = handler.DoMethodReturnString("Search_Exp");
            var url = "";
            if (data.indexOf('err@') == 0) {
                alert(data);
            }

            data = basePath + data;

            window.open(data);
            return;
        }

        ///导入.
        function Imp() {

            var ensName = GetQueryString("EnsName");
            var en = new Entity("BP.Sys.EnCfg", ensName);
            var url = "./Sys/ImpData.htm?EnsName=" + GetQueryString("EnsName") + "&m=" + Math.random();
            if (en.ImpFuncUrl != '')
                url = en.ImpFuncUrl;

            //获取屏幕的长宽
            var W = document.body.clientWidth - 80;
            var H = document.body.clientHeight - 120;
            OpenBootStrapModal(url, "eudlgframe", '导入数据', W, H, "icon-property", null, null, null, function () {
                window.location.href = window.location.href;
            }, null, 'black');
        }

        function Setting() {

            var url1 = "./Sys/SearchSetting.htm?EnsName=" + GetQueryString("EnsName") + "&m=" + Math.random();

            //先判断是否有该笔数据.
            var ensName = GetQueryString("EnsName");
            var en = new Entity("BP.Sys.EnCfg");
            en.SetPKVal(ensName);
            var i = en.RetrieveFromDBSources();
            if (i == 0) {
                en.No = ensName;
                en.Insert();
            }

            var url = "./RefFunc/En.htm?EnName=BP.Sys.EnCfg&No=" + GetQueryString("EnsName") + "&m=" + Math.random();

            //获取屏幕的长宽
            var W = document.body.clientWidth - 340;
            var H = document.body.clientHeight - 40;
            OpenBootStrapModal(url, "eudlgframe", '设置', W, H, "icon-property", null, null, null, null, null, 'black');
        }

        function formatOper(val, rowData, index) {
            var pkval = rowData["No"];
            if (pkval == undefined) {
                pkval = rowData["OID"];
            }
            if (pkval == undefined) {
                pkval = rowData["MyPK"];
            }
            if (pkval == undefined) {
                pkval = rowData["WorkID"];
            }
            if (pkval == undefined) {
                pkval = rowData["NodeID"];
            }

            if (rowData.MyFileName != null && rowData.MyFileName != "")
                return "<a href='#' onclick='downLoadFile(\"" + pkval + "\")' target='_self'>下载</a>";
            else
                return "";
        }

        function openFun(warning, url, title) {
            var W = document.body.clientWidth - 40;
            var H = document.body.clientHeight - 40;
            if (confirm(warning)) {
                OpenBootStrapModal(url, "eudlgframe", title, W, H, "icon-property", null, null, null, null, null, "black");
            }
        }

        function downLoadFile(PKVal) {
            if (plant == "CCFlow")
                window.location.href = '../CCForm/DownFile.aspx?DoType=EntityFile_Load&DelPKVal=' + PKVal + '&EnsName=' + GetQueryString("EnsName");
            else {
                var currentPath = window.document.location.href;
                var path = currentPath.substring(0, currentPath.indexOf('/WF') + 1);
                Url = path + '/WF/Ath/EntityFileLoad.do?DelPKVal=' + PKVal + '&EnsName=' + GetQueryString("EnsName");
                window.location.href = Url;
            }
        }

        function executeFunction(jsString, label) {
            jsString = jsString.replace(/~/g, "'");
            if (jsString.indexOf("/") != -1) {
                var W = document.body.clientWidth - 40;
                var H = document.body.clientHeight - 40;
                OpenBootStrapModal(jsString, "eudlgframe", label, W, H, "icon-property", null, null, null, null, null, 'black');
            } else {
                if (jsString.indexOf('(') == -1)
                    eval(jsString + "()");
                else
                    eval(jsString);
            }
        }

        /* 级联下拉框  param 传到后台的一些参数  例如从表的行数据 主表的字段值 如果param参数在，就不去页面中取KVS 了，PARAM 就是*/
        function DDLRelation(selectVal, ddlChild, fk_mapExt, param) {
            if (selectVal == "all") {
                $("#" + ddlChild).empty();
                //无数据返回时，提示显示无数据，并将与此关联的下级下拉框也处理一遍，edited by liuxc,2015-10-22
                $("#" + ddlChild).append("<option value='all' selected='selected' >全部</option");
                var chg = $("#" + ddlChild).attr("onchange");

                $("#" + ddlChild).change();

                return;
            }

            var mapExt = new Entity("BP.Sys.MapExt", fk_mapExt);

            //处理参数问题
            if (param != undefined) {
                kvs = '';
            }
            var dbSrc = mapExt.Doc;
            if (param != undefined) {
                for (var pro in param) {
                    if (pro == 'DoType')
                        continue;
                    dbSrc = dbSrc.replace("@" + pro, param[pro]);
                }
            }

            var dataObj = GenerDB(dbSrc, selectVal, mapExt.DBType); //获得数据源.

            // 这里要设置一下获取的外部数据.
            // 获取原来选择值.
            var oldVal = null;
            var ddl = document.getElementById(ddlChild);

            if (ddl == null) {
                alert(ddlChild + "丢失,或者该字段被删除.");
                return;
            }


            var mylen = ddl.options.length - 1;
            while (mylen >= 0) {
                if (ddl.options[mylen].selected) {
                    oldVal = ddl.options[mylen].value;
                }
                mylen--;
            }

            //清空级联字段
            $("#" + ddlChild).empty();

            //查询数据为空时为级联字段赋值
            if (dataObj == null || dataObj.length == 0) {
                //无数据返回时，提示显示无数据，并将与此关联的下级下拉框也处理一遍，edited by liuxc,2015-10-22
                $("#" + ddlChild).append("<option value='' selected='selected' >无数据</option");
                var chg = $("#" + ddlChild).attr("onchange");

                if (typeof chg == "function") {
                    $("#" + ddlChild).change();
                }
                return;
            }

            //不为空的时候赋值
            $("#" + ddlChild).append("<option value='all' >全部</option>");
            $.each(dataObj, function (idx, item) {
                var no = item.No;
                if (no == undefined)
                    no = item.NO;

                var name = item.Name;
                if (name == undefined)
                    name = item.NAME;

                $("#" + ddlChild).append("<option value='" + no + "'>" + name + "</option");

            });

            var isInIt = false;
            mylen = ddl.options.length - 1;
            while (mylen >= 0) {
                if (ddl.options[mylen].value == oldVal) {
                    ddl.options[mylen].selected = true;
                    isInIt = true;
                    break;
                }
                mylen--;
            }
            if (isInIt == false) {
                //此处修改，去掉直接选中上次的结果，避免错误数据的产生，edited by liuxc,2015-10-22
                //$("#" + ddlChild).prepend("<option value='' selected='selected' >*请选择</option");
                $("#" + ddlChild).val('');
                //增加默认选择第一条数据
                ddl.options[0].selected = true;
                var chg = $("#" + ddlChild).attr("onchange");
                $("#" + ddlChild).change();

            }
        }
        //打开窗口
        function WinOpenIt(url, winName) {
            //var w = screen.availWidth;
            //var h = screen.availHeight;
            var newWindow = window.open(url, winName, 'height=1200,width=1000,top=' + (window.screen.availHeight - 800) / 2 + ',left=' + (window.screen.availWidth - 1030) / 2 + ',scrollbars=yes,resizable=yes,toolbar=false,location=false,center=yes,center: yes;');
            newWindow.focus();
            return;
        }


    </script>

</head>
<body id="SearchHtml" class="cs-search-html">
    <div class="wrapper wrapper-content animated fadeInRight cs-table" style="padding: 0px 10px 0px 10px">
        <div class="ibox-content">
            <div class="row cs-shadow-box">
                <div class="panel panel-default" style="border: 0px; margin-bottom: 3px">
                    <div id="toolbar" style="width: 100%">
                    </div>
                </div>
            </div>
            <div class="row cs-shadow-box">
                <table id="dg" class="table table-hover" style="word-wrap: break-word; word-break: break-all;">
                </table>
                <!-- 显示分页信息 -->
                <div>
                    <div class="row cs-pagination" style="float:left;width:65%;text-align: left;">
                        <ul class="pagination  controls" style="margin-left:20px"><li class=" controls" id="JsResult"></li></ul>
                    </div>
                    <div class="row cs-pagination" style="float:right;width:35%">
                        <ul class="pagination" id="page_nav"></ul>
                        <ul class="pagination controls" id="page_info"></ul>
                        <div style="clear: both;">
                        </div>
                    </div>
                </div>

            </div>
        </div>
        <div id="Msg">
        </div>
    </div>
</body>
</html>
